const conn = require('../utils/myconn');
//获取所有分类数据
exports.getAllCate = (callback) => {
  let sql = `select * from categories `;
  conn.query(sql, (err, result) => {
    if (err) {
      callback(err)
    } else {
      callback(null, result)
    }
  })

}
//添加分类
exports.addCate=(obj,callback)=>{
  let sql='insert into categories set ?';
  conn.query(sql,obj,(err,result)=>{
    if (err) {
      callback(err)
    } else {
      callback(null)
    }
  })
}
//通过id进行编辑
exports.editCateById=(obj,callback)=>{
  let sql='update categories set ? where id=?';
  conn.query(sql,[obj,obj.id],(err,result)=>{
    if (err) {
      callback(err)
    } else {
      callback(null)
    }
})
}
//通过id进行删除
exports.delCateById=(ids,callback)=>{
  let sql=`delete from categories where id in (${ids})`;
  conn.query(sql,(err,result)=>{
    if (err) {
      callback(err)
    } else {
      callback(null)
    }
})
}


